package com.kb.controller.shtQuote;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.kb.common.ApiResponse;
import com.kb.domain.icQuote.Product;
import com.kb.domain.icQuote.QueryTO;
import com.kb.entity.shtQuote.GoodsData;
import com.kb.service.SHTService;
import com.xxl.job.core.handler.annotation.XxlJob;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


@Controller
@RequestMapping("/SHTQuote")
public class SHTQuoteController {


    @Resource
    private SHTService service;

    @GetMapping("/updateSHTToken")
    @XxlJob("updateSHTToken")
    @ResponseBody
    public ApiResponse updateToken()  {
        service.updateToken();
        return ApiResponse.success("ok");
    }

    @PostMapping("/query")
    @ResponseBody
    public ApiResponse query(@RequestBody QueryTO to) throws JsonProcessingException {

        List<GoodsData> query = service.query(to);

        if(query==null){
            return  ApiResponse.error("错误，未找到相关数据");
        }
        return ApiResponse.successCount(query,query.size());
    }



}
